package com.zd.zjfx;

import java.util.concurrent.Executor;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@EnableAsync
@SpringBootApplication

public class ZjfxApplication extends  SpringBootServletInitializer{

	public static void main(String[] args){
		SpringApplication.run(ZjfxApplication.class, args);
		
	}

	@Bean(name = "threadPoolTaskExecutor")
	public Executor threadPoolTaskExecutor(){
		return new ThreadPoolTaskExecutor();
	}

	@Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ZjfxApplication.class);
    }
	
//	private int corePoolSize = 10;
//    /** Set the ThreadPoolExecutor's maximum pool size. */
//    private int maxPoolSize = 20;
//    /** Set the capacity for the ThreadPoolExecutor's BlockingQueue. */
//    private int queueCapacity = 200;
// 
//    @Bean ("threadPoolTaskExecutor")
//    public TaskExecutor taskExecutor() {
//        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
//        executor.setCorePoolSize(corePoolSize);
//        executor.setMaxPoolSize(maxPoolSize);
//        executor.setQueueCapacity(queueCapacity);
//        executor.setThreadNamePrefix("AlarmExecutor-");
//        executor.setKeepAliveSeconds(60);
//        // rejection-policy：当pool已经达到max size的时候，如何处理新任务
//        // CALLER_RUNS：不在新线程中执行任务，而是有调用者所在的线程来执行
//        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
//        executor.initialize();
//        return executor;
//    }
	
}
